package name.matthewgreet.example4.common; import java.io.Serializable; import java.util.ArrayList; import java.util.List; public abstract class AbstractListDisplay<D,T extends Serializable> { private ListCache<?,?,T> listCache; private List<D> formattedList; private int recordNo; private int listSize; private int pageNo; private int pageSize; private int totalPages; public AbstractListDisplay(ListCache<?,?,T> listCache) { this.listCache = listCache; } protected void formatEnd(ListCache<?,?,T> listCache) { // Empty } protected abstract D formatRecord(T record); protected void formatStart(ListCache<?,?,T> listCache) { // Empty } public void init() throws Exception { List<T> page; page = listCache.getPage(); formattedList = new ArrayList<>(); recordNo = listCache.getSelectedIndex() + 1; listSize = listCache.getListSize(); pageNo = listCache.getPageNo(); pageSize = listCache.getPageSize(); totalPages = listCache.getTotalPages(); formatStart(listCache); for (T record: page) { formattedList.add(formatRecord(record)); } formatEnd(listCache); } public List<D> getFormattedList() { return formattedList; } public int getRecordNo() { return recordNo; } public int getListSize() { return listSize; } public int getPageNo() { return pageNo; } public int getPageSize() { return pageSize; } public int getTotalPages() { return totalPages; } public int getPageStartRecordNo() { return (pageNo - 1) * pageSize + 1; } }